#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================

import os
import torch
import numpy as np


def edge32_hor_c3(input_image):
    height, width, _ = input_image.shape
    output = np.zeros((height, width), dtype=np.uint8)

    # 处理内部区域 (y: 1 to height-2, x: 16 to width-17)
    if height > 2 and width > 31:  # 确保有内部区域可处理
        top_pixels = input_image[0:height - 2, 16:width - 16, :].astype(np.int16)
        bottom_pixels = input_image[2:height, 16:width - 16, :].astype(np.int16)
        gradient = np.abs(bottom_pixels - top_pixels)
        gradient = np.minimum(gradient, 255)
        max_gradient = np.max(gradient, axis=2).astype(np.uint8)
        output[1:height - 1, 16:width - 16] = max_gradient
    return output


def gen_golden_data_simple():

    dtype = np.uint8
    width, height = 4887, 3440

    dtype = np.uint8
    input_shape = [height, width, 3]
    output_shape = [height, width]

    img = np.random.uniform(0, 255, input_shape).astype(dtype)
    
    golden = edge32_hor_c3(img)

    os.system("mkdir -p input")
    os.system("mkdir -p output")
    img.astype(dtype).tofile("./input/input_img.bin")
    golden.tofile("./output/golden.bin")

if __name__ == "__main__":
    gen_golden_data_simple()

